package com.topboya.linker.ui.fragment;

import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.topboya.linker.R;
import com.topboya.linker.diyview.CircleImageView;
import com.topboya.linker.model.response.UserDataResponse;
import com.topboya.linker.ui.activity.NotifyActivity;
import com.topboya.linker.ui.activity.SeeProductInforActivity;
import com.topboya.linker.ui.activity.SettingActivity;
import com.topboya.linker.ui.activity.xCustomerActivity;
import com.topboya.linker.ui.activity.xMainActivity;
import com.topboya.linker.ui.adapter.SelectFileAdapter;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.base.fragment.BaseFragment;
import com.topboya.linker.ui.presenter.UserDataPresenter;
import com.topboya.linker.ui.view.UserDataView;
import com.topboya.linker.utils.LogUtils;
import com.topboya.linker.utils.UIUtils;

public class MessageFragment extends BaseFragment<UserDataView,UserDataPresenter> implements UserDataView {
    private static final String TAG = "MessageFragment-";
    private TextView tv_customer;
    private TextView tv_product;
    private TextView tv_setting;
    private TextView tv_mynotify;
    private xMainActivity mMainActivity;
    private TextView tv_user_name;
    private TextView tv_departname;
    private TextView tv_use_daynum;
    private TextView tv_visit_num;
    private TextView tv_learning_num;
    private TextView tv_sign_num;
    private CircleImageView img_head;
    private String imgbaseurl = "https://otc.topboya.com";


    @Override
    protected int getLayoutId() {

        return R.layout.fragment_message;
    }

    @Override
    protected void initView() {

        tv_customer = mRootView.findViewById(R.id.tv_customer);
        tv_product = mRootView.findViewById(R.id.tv_product);
        tv_setting = mRootView.findViewById(R.id.tv_setting);
        tv_mynotify = mRootView.findViewById(R.id.tv_mynotify);
        tv_user_name = mRootView.findViewById(R.id.tv_user_name);
        tv_departname = mRootView.findViewById(R.id.tv_departname);
        tv_use_daynum = mRootView.findViewById(R.id.tv_use_daynum);
        tv_visit_num = mRootView.findViewById(R.id.tv_visit_num);
        tv_sign_num = mRootView.findViewById(R.id.tv_sign_num);
        tv_learning_num = mRootView.findViewById(R.id.tv_learning_num);
        img_head = mRootView.findViewById(R.id.img_head);

    }
    @Override
    public void initListener() {

        tv_mynotify.setOnClickListener(v -> { mMainActivity.jumpToActivity(NotifyActivity.class) ;});
        tv_customer.setOnClickListener(v -> mMainActivity.jumpToActivity(xCustomerActivity.class));
        tv_product.setOnClickListener(v -> mMainActivity.jumpToActivity(SeeProductInforActivity.class));
        tv_setting.setOnClickListener(v -> mMainActivity.jumpToActivity(SettingActivity.class));

    }
    @Override
    protected void initData() {

        mMainActivity = (xMainActivity) getActivity();
        mPresenter.getUserData();

    }

    @Override
    protected UserDataPresenter createPresenter() {

        return new UserDataPresenter((BaseActivity) getActivity());

    }

    @Override
    public void getUserData(UserDataResponse.Data data) {

        tv_user_name.setText(data.getName());
        tv_departname.setText(data.getOfficeName());
        tv_use_daynum.setText("已使用系统"+data.getLiningDays()+"天");
        tv_sign_num.setText(data.getSignLv()+"%");
        tv_visit_num.setText(data.getActivityNum());
        LogUtils.v(TAG + "data.getPhoto()"+data.getPhoto());
        tv_learning_num.setText(data.getTaskNum());
        Glide.with(mContext).load(imgbaseurl+data.getPhoto()).placeholder(getResources().getDrawable(R.drawable.ic_lanch)).into(img_head);

    }
}
